package com.qf.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class BeanFactory {
    private static Map<String,Object> map = new HashMap<String, Object>();
    //静态代码块，启动时加载
    static {
        //加载属性文件
        try {
            Properties prop = new Properties();
            //获取属性文件的输入流对象
            InputStream resourceAsStream = BeanFactory.class.getResourceAsStream("/bean.properties");
            prop.load(resourceAsStream);

            //创建对象
            Set<String> propertyNames = prop.stringPropertyNames();
            for (String key : propertyNames) {
                String clazzName = prop.getProperty(key);
                //通过反射获取字节码对象
                Class<?> clazz = Class.forName(clazzName);
                //反射创建对象
                Object o = clazz.newInstance();
                //存储到容器中
                map.put(key,o);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

    }
}
